mail-builder
mail-builder is a flexible e-mail builder library written in Rust. It includes the following features:
- Generates e-mail messages conforming to the Internet Message Format standard (RFC 5322).
- Full MIME support (RFC 2045 - 2049) with automatic selection of the most optimal encoding for each message body part.
- Fast Base64 encoding based on Chromium's decoder (the fastest non-SIMD encoder).
- Minimal dependencies.
Please note that this library does not support sending or parsing e-mail messages as these functionalities are provided by the crates mail-send
and mail-parser
.
Usage Example
Build a simple e-mail message with a text body and one attachment:
// Build a simple text message with a single attachment
let eml = new
.from
.to
.subject
.text_body
.attachment
.write_to_string
.unwrap;
// Print raw message
println!;
More complex messages with grouped addresses, inline parts and multipart/alternative sections can also be easily built:
// Build a multipart message with text and HTML bodies,
// inline parts and attachments.
new
.from
// To recipients
.to
// BCC recipients using grouped addresses
.bcc
// Set RFC and custom headers
.subject
.in_reply_to
.header
// Set HTML and plain text bodies
.text_body
.html_body
// Include an embedded image as an inline part
.inline
.attachment
// Add text and binary attachments
.attachment
// Write the message to a file
.write_to
.unwrap;
Nested MIME body structures can be created using the body
method:
// Build a nested multipart message
new
.from
.to
.subject
// Define the nested MIME body structure
.body
// Write the message to a file
.write_to
.unwrap;
Testing
To run the testsuite:
or, to run the testsuite with MIRI:
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Copyright
Copyright (C) 2020-2022, Stalwart Labs Ltd.
See COPYING for the license.